package com.example.qqsave;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Register extends AppCompatActivity implements View.OnClickListener{
    Button btn;
    EditText account,psw, repsw;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        initView();
    }

    private void initView() {
        btn = findViewById(R.id.ok);
        account = findViewById(R.id.account);
        psw = findViewById(R.id.psw);
        repsw = findViewById(R.id.repsw);
        btn.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        String accountStr = account.getText().toString();
        String pswStr = psw.getText().toString();
        String repswStr = repsw.getText().toString();
        if (accountStr.isEmpty()||pswStr.isEmpty()||repswStr.isEmpty()){
            Toast.makeText(this,"你的填写有误",Toast.LENGTH_LONG).show();
        }
        if (pswStr.equals(repswStr)){
            SharedPreferences sp = this.getSharedPreferences("data", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sp.edit();
            editor.putString("userName", accountStr);
            editor.putString("pwd", pswStr);
            editor.commit();
            Toast.makeText(this,"成功",Toast.LENGTH_LONG).show();

            finish();

        }
    }
}
